package com.bjxst;

import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;

/**字符输出流*/
/*IO流中专门提供了用于字符输出的流对象PrintWrite,该对象具有自动行刷新，不用调用flush();
 * 缓冲字符输出流，特点是可以接行写出字符串，并且可通过println()方法实现自动换行*/
public class LineNumber03 {
    public static void main(String[] args) {
        BufferedReader br =null;
        PrintWriter pw =null;
        try{
            br = new BufferedReader(new InputStreamReader(new FileInputStream("d:/b.txt")));
            pw = new PrintWriter("d:/n.txt");
            String temp ="";
            int i =1;
            while ((temp = br.readLine()) != null){
                pw.println(i+","+temp);
                i++;
            }

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try{
                if(br != null)br.close();
                if(pw != null)pw.close();
            }catch (Exception e){
                e.printStackTrace();
            }
        }
    }
}
